<template>
  <div class="my-search">
    <header>

      <router-link to="/released">
        <div class="released"><van-icon color="#fe430d" name="add" /></div>
      </router-link>
      <div class="search">
        <van-search @focus="search" background="transparent" v-model="value" placeholder="请输入搜索关键词" />
      </div>
      <div class="list">
        <router-link to="/classification"><van-icon name="list-switch" /></router-link>
      </div>
      <div>
        <!-- <router-link v-if="token" to="/my">用户名</router-link> -->
        <div class="user-title" v-if="token">
          <img @click="$router.push('/my')" :src="picUrl" :alt="picUrl">
          <!-- <img src="../assets/img/user-title.jpg" alt=""> -->
        </div>
        <router-link v-else to="/login"><van-icon name="user-o" /></router-link>
      </div>
    </header>

  </div>
</template>

<script>
// 初始化（获取存储在本地的所有用户信息）
let sky_users = []
let sky_users_str = localStorage.getItem("SKY_USERS")
if (sky_users_str) {
  // 如果本地有存储用户信息，就把这个存储信息的字符串转成数组
  sky_users = JSON.parse(sky_users_str)
}

export default {
  data() {
    return {
      value: '',
      picUrl: require("../assets/img/user-title.jpg")
    }
  },
  methods: {
    search() {
      this.$router.push({ path: '/search' });
    }
  },
  // 过滤器
  // filters: {
  //   setUserName(value) {
  //     // console.log(value);
  //     return value.slice(0, 4) + "...";
  //   }
  // },
  // 初始化钩子函数
  created() {
    // 赋值
    let token = localStorage.getItem("AUTO_TOKEN");
    this.token = token;
    // let arr = sky_users.filter(item => item.id == token);
    // if (arr) {
    //   // 获取用户名
    //   // this.userName = arr[0].username;
    //   // console.log(arr);
    // }
  },

}
</script>

<style lang="less" scoped>
@import url(../common/less/varible.less);

.my-search {
  width: 100%;
  height: 50px;
  align-items: center;
  display: flex;
  justify-content: space-between;
  box-sizing: border-box;
  margin-bottom: 10px;

  header {
    width: 100%;
    height: 60px;
    margin-top: 5px;
    line-height: 60px;
    background-color: @color;
    font-size: 18px;
    border-bottom: 1px solid @borderColor;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: @pad;

    .released {
      color: @activeColor;
      font-size: 20px;
    }

    .search {
      width: 100%;
    }

    .list {
      margin-right: 15px;
    }

    .user-title>img {
      width: 25px;
      height: 25px;
      border-radius: 50%;
      transform: translateY(-2px);
    }
  }
}
</style>
